/*
 * @Author: long-xinyu2 2192763423@qq.com
 * @Date: 2025-03-11 18:47:55
 * @LastEditors: long-xinyu2 2192763423@qq.com
 * @LastEditTime: 2025-04-02 17:55:42
 * @FilePath: \algorithm\algorithm-training\2025_3_11.cpp
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<string>
#include<string.h>
#include<queue>
#include<math.h>
#include<set>
#include<functional>
#include<bits/stdc++.h>
using namespace std;
#define int long long
//using i128 = __int128_t;
inline int inc(int x, int v, int mod) { x += v;return x >= mod ? x - mod : x; }//代替取模+
#define endl '\n'
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;

const int N = 1e7 + 10, M = 1e5 + 10;
const int mod =  998244353;


inline int read()
{
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
            f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
        x = x * 10 + ch - '0', ch = getchar();
    return x * f;
}

int a,b,c,d;
int n = 21;
int func(int a,int b,int c,int d)
{
    if(a == b || c == d) return 0;
    if(b - a > d - c) return func(c,d,a,b);
    int res = 0;
    for(int x = a; x < b;)
    {
        int tt = 0;
        tt = __countr_zero((unsigned)x);
        int ro = min(n,tt);
        while((x + (1 << ro)) > b) ro --;
        int wid = 1 << ro;
        int to = (c >> ro << ro);
        int t1 = (d >> ro << ro);
        if(to < c) to += wid;
        if(t1 >= to) res += (t1 - to) / wid;
        res += func(x,x + wid,c,to) + func(x,x + wid,t1,d);
        x += wid;
    }
    return res;

}

void solve() {
    cin >> a >> b >> c >> d;
    cout << func(a,b,c,d) << endl;
}	
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int tt;
    cin >> tt;
    //tt = 1;
    while (tt--)
    {
        solve();
    }
}